﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Tesla.Validador;

namespace Rendiciones.Logica.Modelos.Validaciones
{
    internal class ValorNoPuedeSerCero : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value == null)
                return new UsefullValidationResult(new[] { validationContext.MemberName }, EValidationResolution.Success);

            if (value is int)
            {
                var valor = (int) value;
                if (valor == 0)
                    return new UsefullValidationResult(new[] {validationContext.MemberName}, EValidationResolution.Error,
                                                       ErrorMessage);
                return new UsefullValidationResult(new[] {validationContext.MemberName}, EValidationResolution.Success);
            }
            else
                //throw new ValidationException("La validación no es compatible con el valor que esta utilizando");
                return new UsefullValidationResult(new[] {validationContext.MemberName}, EValidationResolution.Error);

        }
    }
}